package com.umpay.sp.saas.action.storeManage;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Preparable;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.umpay.operation.common.ReqMessage;
import com.umpay.operation.common.ResMessage;
import com.umpay.operation.common.RetCode;
import com.umpay.operation.model.applet.MerchantInfo;
import com.umpay.operation.model.edrawInf.EdrawInf;
import com.umpay.operation.model.product.MerProduct;
import com.umpay.operation.model.qrConf.QrConf;
import com.umpay.operation.model.spapplyplat.AppChannel;
import com.umpay.operation.model.spapplyplat.JoinFlow;
import com.umpay.operation.service.applet.StoreInfServiceRemote;
import com.umpay.operation.service.edrawInf.remote.EdrawInfServiceRemote;
import com.umpay.operation.service.product.MerProductServiceRemote;
import com.umpay.operation.service.qrConf.remote.QrConfServiceRemote;
import com.umpay.operation.service.spapplyplat.remote.AppChannelServiceRemote;
import com.umpay.operation.service.spapplyplat.remote.JoinFlowServiceRemote;
import com.umpay.operation.web.util.RandomCode;
import com.umpay.operation.xml.XmlData;
import com.umpay.sp.common.LoggerManager;
import com.umpay.sp.helper.ProviceCityInfHelper;
import com.umpay.sp.model.offlinepay.ProviceCityInf;
import com.umpay.sp.saas.util.DesIDUtil;
import com.umpay.sp.saas.util.DubboInvokerUtil;
import com.umpay.sp.saas.util.HttpUtils;
import com.umpay.sp.saas.util.ReqMessageUtil;
import com.umpay.sp.saas.util.SaasPropertyUtil;
import com.umpay.sp.saas.util.ZipUtil;
import com.umpay.sp.saas.vo.JoinFlowVo;
import com.umpay.sp.saas.vo.MerchantInfoVo;
import com.umpay.sp.saas.vo.StoreInfo;
import com.umpay.sp.util.SerialUtil;
import com.umpay.sp.util.StringUtil;
import com.umpay.sp.web.action.sys.BaseAction;
import com.umpay.sp.web.util.PageView;
import com.umpay.sp.web.util.PropertyUtil;
/**
 * 立码付商户管理模块
 * @author css
 *
 */
public class StoreManageAction extends BaseAction implements Preparable{
	
	public final static Logger logger = LoggerManager.getBusiLogger();
	
	HttpServletRequest request = ServletActionContext.getRequest();
	HttpServletResponse response = ServletActionContext.getResponse();
	//店铺信息接口
	StoreInfServiceRemote storeInfServiceRemote = DubboInvokerUtil.getInvoker(StoreInfServiceRemote.class);
	//渠道接口
	AppChannelServiceRemote appChannelServiceRemote = DubboInvokerUtil.getInvoker(AppChannelServiceRemote.class);
	//处理流程接口
	JoinFlowServiceRemote joinFlowServiceRemote = DubboInvokerUtil.getInvoker(JoinFlowServiceRemote.class);
	
	private PageView pageView ;
	private  List<ProviceCityInf> provinceList;
	public  Map<String,Object> queryMap=new HashMap<String, Object>();
	private File downloadFile; //下载文件
	private String downloadFileName;//下载文件名
	private String storeId;
	private String storeshortname;
	private String payeename;
	private String storeType;
	private String intimeStart;
	private String intimeEnd;
	private String registerProcsState;
	private String agentId;
	private String payeeMobileId;
	private String type;
	private String merId;
	private String isDel;
	
	/**
	 * 跳转到立码付商户信息显示页面
	 */
	public String storeManageListView(){
		logger.info("跳转进入立码付商户信息页");
		return "storeManageCtrl";
	}
	
	
	public void prepare() throws Exception {
	}
	
	/**
	 * 立码付商户列表查询接口
	 * @author css
	 */
	public String queryStoreList(){
		logger.info("【查询立码付商户列表接口】开始");
		try {
			String paramPage = request.getParameter("currentPage") == null ? "1" : request.getParameter("currentPage");
			pageView = new PageView(Integer.parseInt(paramPage));
//			String merId = request.getParameter("merId");
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~店铺部署列表详情接口，获得商户店铺列表~~~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage req =ReqMessageUtil.makeOpReq();
			req.put("currentPage",pageView.getCurrentpage());
			req.put("pageSize",pageView.getMaxresult());
			req.put("isDel","0");
			if(StringUtil.isNotEmpty(merId)){
				req.put("merId",merId);
			}
			if(StringUtil.isNotEmpty(storeId)){
				req.put("storeId",storeId);
			}
			if(StringUtil.isNotEmpty(type)){
				req.put("type",type);
			}
			if(StringUtil.isNotEmpty(storeshortname)){
				req.put("storeShortName",storeshortname);
			}
			if(StringUtil.isNotEmpty(payeename)){
				req.put("payeeName",payeename);
			}
			if(StringUtil.isNotEmpty(storeType)){
				req.put("storeType",storeType);
			}
			if(StringUtil.isNotEmpty(intimeStart)){
				req.put("intimeStart",intimeStart);
			}
			if(StringUtil.isNotEmpty(intimeEnd)){
				req.put("intimeEnd",intimeEnd);
			}
			if(StringUtil.isNotEmpty(registerProcsState)){
				if(registerProcsState.equals("00")){//已删除
					req.put("isDel","1");
				}else{
				req.put("registerProcsState",registerProcsState);
				}
			}
			if(StringUtil.isNotEmpty(agentId)){
				req.put("agentId",agentId);
			}
			if(StringUtil.isNotEmpty(payeeMobileId)){
				req.put("payeeMobileId",payeeMobileId);
			}
//			req.put("registerProcsStates","'02','03','04','05','06','07','08','09','10'");
			logger.info("【店铺部署详情列表接口】入参："+ req);
			com.umpay.operation.common.ResMessage res = storeInfServiceRemote.getStoreInfList(req);
			logger.info("【店铺部署详情列表接口】出参："+ res);
			if(!"0000".equals(res.getRetCode())){
				logger.info("获取店铺列表失败！");
				return ERROR;
			}
			List<MerchantInfo> storeList = (List<MerchantInfo>) res.getResMap().get("storeInfList");
			String totalSize = StringUtil.trim(res.getResMap().get("totalSize"));
			if(StringUtil.isEmpty(totalSize) || totalSize.equals("0")){
				logger.info("店铺列表为空！");
				pageView.setRecords(storeList);
				return "batchMerchantList";
			}
			//遍历店铺列表，判断代理商级别,非一级代理商的需查出代理商名称
			List<com.umpay.sp.saas.vo.StoreInfo > newStoreinfoList = new ArrayList<com.umpay.sp.saas.vo.StoreInfo>();
			for(MerchantInfo newStore : storeList ){
				StoreInfo newstoreInfoo = new StoreInfo();
				if(null == newStore.getIsDel() || "1".equals(newStore.getIsDel())){
					newstoreInfoo.setIsDel("1");
				}else{
					newstoreInfoo.setIsDel("0");
				}
				String agentId = StringUtil.trim(newStore.getAgentId());
				logger.info("店铺" + newStore.getStoreId() +"的代理商为：" + agentId);
				if(StringUtil.isNotEmpty(agentId)){
					//~~~~~~~~~~~~~~~~~~~~~查询代理商多级关系接口，判断是几级代理商~~~~~~~~~~~~~~~~~~~~~~
					Map<String,Object> reqMap=new HashMap<String,Object>();
					String rpidCrm = "sPweb" + SerialUtil.getRpid("merRpid", 10);
					reqMap.put("rpid", rpidCrm);
					reqMap.put("agentId",agentId);
					reqMap.put("relType","4");
					String url=PropertyUtil.getStrValue("spEnterpriseWeb_config.properties", "saas.crm.QueryAgentRel.url");//查询代理商多级关系
					logger.info("查询多级代理商url" + url );
					logger.info("【查询多级代理商接口】入参："+ reqMap);
					XStream xstream = new XStream(new DomDriver());
			        Map<String,Object> crmresMap=(Map<String, Object>)HttpUtils.getResObjPost(url, xstream, reqMap);
			        logger.info("【查询多级代理商接口】出参："+ crmresMap);
			        if("00060512".equals(crmresMap.get("retCode"))){
						newstoreInfoo.setAgent2(null);
		        		newstoreInfoo.setAgent3(null);
		        	}
			        if(!"00060512".equals(crmresMap.get("retCode")) && (crmresMap==null ||crmresMap.size()<1 || !"0000".equals(crmresMap.get("retCode")))){
			        	logger.info("调用CRM查询多级代理商关系接口失败");
			        	return ERROR;
			        }
			        //代理商元数据map
					if("0000".equals(crmresMap.get("retCode"))){
						Map<String,Object> agentMetaMap=new HashMap<String,Object>();
						agentMetaMap=(Map<String,Object>) crmresMap.get("agentMetaMap");
						//代理商级别
						String agencyLevel = StringUtil.trim(agentMetaMap.get("minLevel"));
						logger.info("代理商最低级别为:" + agencyLevel);
						//二级代理商
						if("2".equals(agencyLevel)){
							Map<String,Object> agentMap=new HashMap<String,Object>();
							agentMap = (Map<String, Object>) crmresMap.get("agentMap");
							Map<String,Object> agentDataMap=(Map<String,Object>) agentMap.get(agentId);
							String agentName2 = StringUtil.trim(agentDataMap.get("agentName"));
							newstoreInfoo.setAgent2(agentName2);
						}
						if("3".equals(agencyLevel)){
							Map<String,Object> supAgentLevelRelMap=new HashMap<String,Object>();
							supAgentLevelRelMap = (Map<String, Object>) crmresMap.get("supAgentLevelRelMap");
							List<String> list=(List<String>) supAgentLevelRelMap.get(agentId);
							String agencyId2 = list.get(0);
							//获取二级代理商名称s
							Map<String,Object> agentMap=new HashMap<String,Object>();
							agentMap = (Map<String, Object>) crmresMap.get("agentMap");
							Map<String,Object> agentDataMap2=(Map<String,Object>) agentMap.get(agencyId2);
							String agentName2 = StringUtil.trim(agentDataMap2.get("agentName"));
							//获取三级代理商名称
							Map<String,Object> agentDataMap3=(Map<String,Object>) agentMap.get(agentId);
							String agentName3 =StringUtil.trim(agentDataMap3.get("agentName"));
							newstoreInfoo.setAgent3(agentName3);
						}
					}
				}
				logger.info("代理商编号为空，不做代理商信息查询");
				//~~~~~~~~~~~~~~~~~~~~查询店铺处理信息流程接口~~~~~~~~~~~~~~~~~~~~~~~
				com.umpay.operation.common.ReqMessage reqOp = ReqMessageUtil.makeOpReq();
				reqOp.put("merUniformId",StringUtil.trim(newStore.getStoreId()));
//				reqOp.put("handleRole", "02");
				reqOp.put("handleStep","待审核");
				logger.info("【查询店铺处理信息流程接口】入参：" + reqOp);
				JoinFlowServiceRemote joinFlowServiceRemote = DubboInvokerUtil.getInvoker(JoinFlowServiceRemote.class);
				com.umpay.operation.common.ResMessage resOp = joinFlowServiceRemote.queryJoinFlowList(reqOp);
				logger.info("【查询店铺处理信息流程接口】出参：" + resOp);
				if(!"0000".equals(resOp.getRetCode())){
					logger.info("查询店铺处理信息流程接口失败！");
					return ERROR;
				}
				List<JoinFlow> joinFlowList = (List<JoinFlow>) resOp.getResMap().get("joinFlowList");
				if(joinFlowList==null||joinFlowList.size()==0){
					logger.info("查询流转表信息，暂无数据");
				}else{
					logger.info(String.format("----★----★--根据店铺编号查询流转信息列表，joinFlowList:", joinFlowList));
					List<JoinFlowVo> joinFlowVoList=new ArrayList<JoinFlowVo>();
					List<JoinFlowVo> joinFlowVoList1=new ArrayList<JoinFlowVo>();//复审开通成功 待修改(初次审核时间)
					List<JoinFlowVo> joinFlowVoList2=new ArrayList<JoinFlowVo>();//自动审核通过待审查（初次待审核时间）
					for(JoinFlow joinFlow:joinFlowList){
						JoinFlowVo joinFlowVo=new JoinFlowVo();
						SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
						joinFlowVo.setHandleUser(joinFlow.getHandleUser());
						Date date=sdf.parse(joinFlow.getIntime());
						joinFlowVo.setIntime(sdf.format(date));
						joinFlowVo.setReason(joinFlow.getRemark());
						if(joinFlow.getHandleStep().equals("店铺信息审核成功")){
							joinFlowVoList1.add(joinFlowVo);
						}else if(joinFlow.getHandleStep().equals("店铺信息驳回成功")){
							joinFlowVoList1.add(joinFlowVo);
						}else if(joinFlow.getHandleStep().equals("自动开通待复查")){
							joinFlowVoList2.add(joinFlowVo);
						}else if(joinFlow.getHandleStep().equals("待复查")){
							joinFlowVoList.add(joinFlowVo);
						}
					}
					if(joinFlowVoList1.size()>=1){ 
						Collections.sort(joinFlowVoList1);
						String auditTime =joinFlowVoList1.get(0).getIntime();//初次审核时间
						newstoreInfoo.setAuditTime(auditTime);
					}
					if(joinFlowVoList2.size()>=1){
						Collections.sort(joinFlowVoList2);
						String pendingTime =joinFlowVoList2.get(0).getIntime();//初次待审核时间
						newstoreInfoo.setPendingTime(pendingTime);
					}
				}
				newstoreInfoo.setStoreId(newStore.getStoreId());//商户编号
				newstoreInfoo.setStoreShortName(newStore.getStoreShortName());//店铺名称
				newstoreInfoo.setType(newStore.getType());//入网类型
				newstoreInfoo.setIntime(newStore.getIntime());//入网时间
				newstoreInfoo.setPayeeName(newStore.getPayeeName());//收款人姓名
				newstoreInfoo.setRegisterProcsState(newStore.getRegisterProcsState());//状态
				newstoreInfoo.setStoreType(newStore.getStoreType());//商户类型
				newstoreInfoo.setMerId(newStore.getMerId());//商户号
				newStoreinfoList.add(newstoreInfoo);
			}
			Map<String, Object> resMQ = new HashMap<String, Object>();
			resMQ.put("list", newStoreinfoList);
			logger.info("输出的店铺列表为：" + newStoreinfoList );
			
			pageView.setTotalrecord(Integer.valueOf(totalSize));
			pageView.setRecords(newStoreinfoList);
			return "batchMerchantList";		
		} catch (Exception e) {
			logger.error("查询商户列表失败",e);
			return ERROR;
		}
	}
	
	/**
	 * 立码付商户详情查看接口
	 */
	public String stroeInfoQuery(){
		logger.info("【立马付商户详情查询接口】开始");
		if(pageView == null ){
			pageView = new PageView();
		}
		Map<String , Object> resMap  = new HashMap<String , Object>();
		try {
			String merId = StringUtil.trim(request.getParameter("merId"));
			String storeId = StringUtil.trim(request.getParameter("storeId"));
			if(StringUtil.isEmpty(merId)){
				logger.info("获取商户号为空！");
				return ERROR;
			}
			if(StringUtil.isEmpty(storeId)){
				logger.info("获取店铺号为空！");
				return ERROR;
			}
			//~~~~~~~~~~~~~~~~~~~~~~店铺部署详情接口，查询店铺信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage req = ReqMessageUtil.makeOpReq();
			req.getReqMap().put("storeId", storeId);
			logger.info("【查询店铺部署详情接口】入参：" + req);
			ResMessage res = storeInfServiceRemote.getStoreInfByPri(req);
			logger.info("【查询店铺部署详情接口】出参：" + res);
			if( !RetCode.SUCCESS.equals(res.getRetCode())){
				logger.info("查询店铺部署详情接口失败！");
				return ERROR;
			}
			MerchantInfo merchantInfo = (MerchantInfo) res.getResMap().get("merchantInfo");
			if(merchantInfo ==null ||merchantInfo.equals("")){		//无数据
				logger.info("查询收款人信息无数据merId："+merId);
				resMap.put("merchantInfo", null);
//				return ERROR;
			}
			if(null !=merchantInfo ){
				String payeeInidcard = StringUtil.trim(merchantInfo.getPayeeInidcard());
				payeeInidcard = DesIDUtil.desID2Star(payeeInidcard);
				merchantInfo.setPayeeInidcard(payeeInidcard);
				String preMobile = StringUtil.trim(merchantInfo.getPreStorePhone());
				if(null != preMobile){
					preMobile= DesIDUtil.ID4Star(preMobile);
					merchantInfo.setPreStorePhone(preMobile);
				}
			}
			resMap.put("merchantInfo", merchantInfo);
			//~~~~~~~~~~~~~~~~~~~~~~查询商户绑卡信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage reqEd = ReqMessageUtil.makeOpReq();
			EdrawInfServiceRemote edrawInfRemote = DubboInvokerUtil.getInvoker(EdrawInfServiceRemote.class);
			Map<String, Object> reqMap = new HashMap<String, Object>();
			reqMap.put("merId", merId);
			reqMap.put("delayDays", 1);
			reqMap.put("state", "2");
			reqEd.setReqMap(reqMap);
			logger.info("查询商户绑定银行卡信息接口入参：" + req);
			com.umpay.operation.common.ResMessage resEd = edrawInfRemote.queryEdrewInf(reqEd);
			logger.info("查询商户绑定银行卡信息接口出参：" + resEd);
			if( !RetCode.SUCCESS.equals(resEd.getRetCode())){
				logger.info("立码付信息详情查询接口失败！");
				return ERROR;
			}
 			EdrawInf edrawInfReData =(EdrawInf) resEd.getResMap().get("edrawInf");
			if(null == edrawInfReData){
				logger.info("商户未绑定银行卡！");
				resMap.put("EdrawInfReData", null);
			}
			logger.info("商户绑定银行卡:"+ edrawInfReData);
			Map<String, Object> resEdMap = new HashMap<String, Object>();
			if( null != edrawInfReData){
				resEdMap.put("bankName",StringUtil.trim(edrawInfReData.getBankName()));
				String bankAccount = StringUtil.trim(edrawInfReData.getBankAccount());
				bankAccount= DesIDUtil.ID3Star(bankAccount);
				resEdMap.put("bankAccount",bankAccount);
				resMap.put("EdrawInfReData", resEdMap);
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~查询渠道表接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\
			logger.info("调用查询渠道开通接口");
			ReqMessage reqq = ReqMessageUtil.makeOpReq();
			reqq.getReqMap().put("appSysId", storeId);
			String storeIdProductId = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","productIDs-zishanghu");
			reqq.getReqMap().put("productIds",storeIdProductId );
			logger.info("【查询渠道开通接口】入参：" + reqq);
			ResMessage ress =appChannelServiceRemote.getAppChannelListByProductids(reqq);
			logger.info("【查询渠道开通接口】出参：" + ress);
			if(!"0000".equals(ress.getRetCode())){
				logger.info("查询渠道接口失败！");
				return ERROR;
			}
			List<AppChannel> appList = (List<AppChannel>) ress.getResMap().get("appChannels");
			AppChannel appchannel = null;
			if(null!= appList && 0 < appList.size() ){
				appchannel = appList.get(0);
			}
			if( null == appList || null == appchannel){
				logger.info("查询渠道接口为空！appList：" + appList);
				resMap.put("rateZFB", null);
				resMap.put("rateWX", null);
			}
			if(null != appchannel){
				String rateZFB = appchannel.getAlipayRates();
				String rateWX = appchannel.getWecatRates();
				resMap.put("rateZFB",  Double.valueOf(rateZFB)/1000);
				resMap.put("rateWX", Double.valueOf(rateWX)/1000);
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~查询二维码配置接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage reqE = ReqMessageUtil.makeOpReq();
			QrConfServiceRemote qrConfServiceRemote = DubboInvokerUtil.getInvoker(QrConfServiceRemote.class);
			reqE.put("merId",storeId);
			logger.info("【查询二维码配置接口】入参：" + reqE);
			com.umpay.operation.common.ResMessage resE = qrConfServiceRemote.queryQrConfByMerId(reqE);
			logger.info("【查询二维码配置接口】出参：" + resE);
			
			if( !"0000".equals(resE.getRetCode()) && !"00100003".equals(resE.getRetCode())){
				logger.info("查询二维码配置接口失败！");
				return ERROR;
			}
//			if("00100003".equals(resE.getRetCode())){
//				logger.info("查询二维码配置为空！");
//				resMap.put("qrCodeList", null);
//			}
			Map<String, Object> map1 = resE.getResMap();
			List<QrConf> qrList =((List<QrConf>) map1.get("qrList"));
			if(qrList !=null && qrList.size()>0){
				String[] qrCodeList=new String[qrList.size()];
				int i=0;
				for (QrConf qrConf : qrList) {
					qrCodeList[i]=qrConf.getQrId();
					i++;
				}
				resMap.put("qrCodeList", qrCodeList);
			}else{
				resMap.put("qrCodeList", null);
			}
			List<Map<String , Object>> resList = new ArrayList<Map<String,Object>>();
			provinceList = ProviceCityInfHelper.getAllProvice();
			resList.add(resMap);
			pageView.setRecords(resList);
			return "merchantLook";
		} catch (Exception e) {
			logger.error("立马付商户信息详情查询接口失败！",e);
		}
		return ERROR;
	}
	/**
	 * 立码付删除接口
	 * @return
	 */
	public String  storeInfDel(){
		logger.info("【立码付删除接口】开始");
		try {
			String merId = StringUtil.trim(request.getParameter("merId"));
			String storeId = StringUtil.trim(request.getParameter("storeId"));
			if(StringUtil.isEmpty(merId)){
				logger.info("获取商户号为空！");
				return ERROR;
			}
			if(StringUtil.isEmpty(storeId)){
				logger.info("获取店铺号为空！");
				return ERROR;
			}
			//~~~~~~~~~~~~~~~~~~~~~~查询该收款人下所有店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage  reqMe = ReqMessageUtil.makeOpReq();
			reqMe.put("merId" ,merId);
			reqMe.put("isDel","0");
			logger.info("【查询商铺列表接口】入参：" + reqMe);
			com.umpay.operation.common.ResMessage resMe = storeInfServiceRemote.getStoreInfList(reqMe);
			logger.info("【查询商铺列表接口】出参：" + resMe);
			if( !"0000".equals(resMe.getRetCode())){
				logger.info("查询店铺列表接口调用失败！");
				return ERROR;
			}
			Integer totalSize = (Integer) resMe.getResMap().get("totalSize");
			List<MerchantInfo> storeInfs = (List<MerchantInfo>) resMe.getResMap().get("storeInfList");
			MerchantInfo merchantInfo = null;
			for(MerchantInfo storeDef : storeInfs){
				if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
					merchantInfo = storeDef;
					break;
				}
			}
			String defultStore = merchantInfo.getDefultStore();
			//1.删除店铺
			if(del(merchantInfo)){
				logger.info("删除店铺成功！" + storeId);
			}else{
				logger.info("删除店铺失败：" + storeId);
				return ERROR;
			}
			//2.当前店铺为默认店铺且有多家店铺时，更新新的默认店铺
			if("0".equals(defultStore) && totalSize > 1){
				MerchantInfo newStoreDef = null;
				MerchantInfo newStoreDef8 = null;
				MerchantInfo newStoreDef7 = null;
				MerchantInfo newStoreDef9 = null;
				MerchantInfo newStoreDef6 = null;
				MerchantInfo newStoreDef10 = null;
				for(MerchantInfo storeDef : storeInfs){
					if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
						continue;
					}
					String state = StringUtil.trim(storeDef.getRegisterProcsState());
					newStoreDef = storeDef;
					if("08".equals(state)){
						newStoreDef8 = storeDef;
					}else if("07".equals(state)){
						newStoreDef7 = storeDef;				
					}else if("09".equals(state)){
						newStoreDef9 = storeDef;
					}else if("06".equals(state)){
						newStoreDef6 = storeDef;
					}else if("10".equals(state)){
						newStoreDef10 = storeDef;
					}
				}
				if(newStoreDef8 != null){
					newStoreDef = newStoreDef8;
				}else if(newStoreDef7 != null){
					newStoreDef = newStoreDef7;				
				}else if(newStoreDef9 != null){
					newStoreDef = newStoreDef9;
				}else if(newStoreDef6 != null){
					newStoreDef = newStoreDef6;
				}else if(newStoreDef10 != null){
					newStoreDef = newStoreDef10;
				}
				//~~~~~~~~~~~~~~~~~~~~~~~~~~修改默认店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~
				newStoreDef.setDefultStore("0");
				Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(newStoreDef);	
				ReqMessage reqUp = ReqMessageUtil.makeOpReq();
				reqUp.putAll(storeMap3);
				logger.info("【修改店铺信息接口】入参：" + reqUp);
				ResMessage resUp =  storeInfServiceRemote.updateStoreInfAll(reqUp);
				logger.info("【修改店铺信息接口】出参：" + resUp);
				if(!"0000".equals(resUp.getRetCode())){
					logger.info("修改默认店铺失败！");
					return ERROR;
				}
			}
			logger.info("修改默认店铺成功！");
			response.getWriter().write("0");
			return null;
		} catch (Exception e) {
			logger.error("立码付商户接口失败！",e);
		}	
		return ERROR;
	}

	/**
	 * 删除店铺子方法
	 * @param merchant
	 * @return
	 */
	public boolean del(MerchantInfo merchant){
		MerchantInfo merchantInfo = merchant;
		try {
			//配置文件读取子商户对应产品号
			String storeIdProductId = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","storeId.bProductId");
			String stateDel = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","storeId.bProductId.state");
			String url = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","cancelUrlStr");
			String[] productIds = storeIdProductId.split("&");
			MerProductServiceRemote merProductRemote =  DubboInvokerUtil.getInvoker(MerProductServiceRemote.class);
			for(String productId:productIds){
				logger.info("注销产品关系，开始的产品号是:"+productId);
				//~~~~~~~~~~~~~~~~~~~~~根据主键查询商户商品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				com.umpay.operation.common.ReqMessage reqOp = ReqMessageUtil.makeOpReq();
				reqOp.put("merId",storeId);
				reqOp.put("productId",productId);
				logger.info("【根据主键查询商户商品关系接口】入参："+ reqOp);
				com.umpay.operation.common.ResMessage resOp = merProductRemote.getMerProductByKey(reqOp);
				logger.info("【根据主键查询商户商品关系接口】出参："+ resOp);
				if( !RetCode.SUCCESS.equals(resOp.getRetCode())){
					logger.info("根据主键查询商户商品关系接口调用失败：");
					return false;
				}
				MerProduct merProduct = (com.umpay.operation.model.product.MerProduct) resOp.getResMap().get("merProduct");
				if(merProduct != null){
					//~~~~~~~~~~~~~~~~~~~~~注销产品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					logger.info("商户已开通此产品:" + productId );
					String cancelUrlStr = url + "UnRegMerAccount/"+ "MerProductStateCancel.xml";
					logger.info("注销产品关系请求url：" + url);
					Map<String,Object> reqMap=new HashMap<String,Object>();
					String rpidCrm = "sPweb" + SerialUtil.getRpid("merRpid", 10);
					reqMap.put("rpid", rpidCrm);
					reqMap.put("merId",storeId);
					reqMap.put("productId",productId);
					logger.info("【注销产品关系接口】入参："+ reqMap);
					XStream xstream = new XStream(new DomDriver());
			        Map<String,Object> crmresMap=(Map<String, Object>)HttpUtils.getResObjPost(cancelUrlStr, xstream, reqMap);
			        logger.info("【注销产品关系接口】出参："+ crmresMap);
			        if (!("0000".equals(StringUtil.trim(crmresMap.get("retCode")))) && !"00060403".equals(StringUtil.trim(crmresMap.get("retCode")))) {
						logger.info("通过crm注销产品关系失败");
						return false;
			        }
			        if( "00060403".equals(StringUtil.trim(crmresMap.get("retCode")))){
			        	logger.info("用户本处于注销状态");
			        }
					logger.info("注销商户产品关系成功storeId:" + storeId+ "productId：" + productId);
				}
				if(merProduct == null){
					logger.info("商户未开通此产品storeId：" + storeId + "productId:" + productId);
				}
				}
			//~~~~~~~~~~~~~~~~~~~~~修改店铺信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage reqStor = ReqMessageUtil.makeOpReq();
			merchantInfo.setIsDel("1");
			Map<String, Object> storeMap3 = SaasPropertyUtil.javaBeanToMapO(merchantInfo);	
			reqStor.putAll(storeMap3);
			logger.info("【修改店铺信息接口】入参：" + reqStor);
			ResMessage resStor =  storeInfServiceRemote.updateStoreInfAll(reqStor);
			logger.info("【修改店铺信息接口】出参：" + resStor);
			if(!"0000".equals(resStor.getRetCode())){
				logger.info("修改店铺信息接口调用失败！");
				return false;
			}
			//~~~~~~~~~~~~~~~~~~~~~~~增加处理流程信息~~~~~~~~~~~~~~~~~~~~~~
			String agentId= StringUtil.trim(this.getSession().get(XmlData.AGENTID));
			ReqMessage reqJoin = ReqMessageUtil.makeOpReq();
			reqJoin.put("merUniformId",storeId);	//商户唯一标识
			reqJoin.put("handleState","0");	//申请处理状态   0-初始 1-完成
			reqJoin.put("handleStep","已删除");	//处理节点  中文描述
			reqJoin.put("handleRole","00");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他		
			reqJoin.put("handleUser",agentId);	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他		
			logger.info("【增加审批流程接口（删除记录）】入参：" + reqJoin);
			ResMessage resJoin = joinFlowServiceRemote.add(reqJoin);
			logger.info("【增加审批流程接口（删除记录）】出参：" + resJoin);
			if(!"0000".equals(resJoin.getRetCode())){
				logger.info("增加审批流程接口调用失败！");
				return false;
			}
			logger.info("增加审批流程（已删除）成功！");
			logger.info("修改店铺信息接口成功！已删除店铺：" + storeId);
			return true;
		} catch (Exception e) {
			logger.error("删除店铺失败！",e);
			return false;
		}
	}
	
	/**
	 * 修改立码付商户初始化接口
	 * @return
	 */
	public String stroeInfoInitialize(){
		logger.info("【修改立码付商户初始化接口】开始");
		if(pageView == null ){
			pageView = new PageView();
		}
		Map<String , Object> resMap = new HashMap<String, Object>();
		try {
//			String storeId = StringUtil.trim(request.getParameter("storeId"));
			if(StringUtil.isEmpty(storeId)){
				logger.info("获取店铺号为空！");
				return ERROR;
			}
			//~~~~~~~~~~~~~~~~~~~~~~店铺部署详情接口，查询店铺信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage req = ReqMessageUtil.makeOpReq();
			req.put("storeId",storeId);
			logger.info("【查询店铺部署详情接口】入参：" + req);
			ResMessage  res = storeInfServiceRemote.getStoreInfByPri(req);
			logger.info("【查询店铺部署详情接口】出参：" + res);
			if(!"0000".equals(res.getRetCode())){
				logger.info("查询店铺部署详情接口失败！");
				return ERROR;
			}
			MerchantInfo merchantInfo = (MerchantInfo) res.getResMap().get("merchantInfo");
			if(merchantInfo ==null ||merchantInfo.equals("")){		//无数据
				logger.info("查询店铺信息详情无数据");
				return ERROR;
			}
			if(null !=merchantInfo  ){
				String payeeInidcard = StringUtil.trim(merchantInfo.getPayeeInidcard());
				payeeInidcard = DesIDUtil.desID2Star(payeeInidcard);
				merchantInfo.setPayeeInidcard(payeeInidcard);
			}
			resMap.put("storInfo", merchantInfo);
			//~~~~~~~~~~~~~~~~~~~~~~~~~查询渠道表接口（获取费率）~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("调用查询渠道开通接口");
			ReqMessage reqq = ReqMessageUtil.makeOpReq();
			reqq.getReqMap().put("appSysId", storeId);
			String storeIdProductId = PropertyUtil.getStrValue("spEnterpriseWeb_config.properties","productIDs-zishanghu");
			reqq.getReqMap().put("productIds",storeIdProductId );
			logger.info("【查询渠道开通接口】入参：" + reqq);
			AppChannelServiceRemote appChannelServiceRemote = DubboInvokerUtil.getInvoker(AppChannelServiceRemote.class);
 			ResMessage ress =appChannelServiceRemote.getAppChannelListByProductids(reqq);
			logger.info("【查询渠道开通接口】出参：" + ress);
			if(!"0000".equals(ress.getRetCode())){
				logger.info("查询渠道接口失败！");
				return ERROR;
			}
			List<AppChannel> appList = (List<AppChannel>) ress.getResMap().get("appChannels");
			AppChannel appchannel = null;
			if(null!= appList && 0 < appList.size() ){
				appchannel = appList.get(0);
			}
			if( null == appList || null == appchannel){
				logger.info("查询渠道接口为空！appList：" + appList);
				resMap.put("rateZFB", null);
				resMap.put("rateWX", null);
			}
			if(null != appchannel){
				String rateZFB = appchannel.getAlipayRates();
				String rateWX = appchannel.getWecatRates();
				resMap.put("rateZFB",  Double.valueOf(rateZFB)/1000);
				resMap.put("rateWX", Double.valueOf(rateWX)/1000);
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~查询二维码配置接口（查询二维码）~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage reqE = ReqMessageUtil.makeOpReq();
			QrConfServiceRemote qrConfServiceRemote = DubboInvokerUtil.getInvoker(QrConfServiceRemote.class);
			reqE.put("merId",storeId);
			logger.info("【查询二维码配置接口】入参：" + reqE);
			com.umpay.operation.common.ResMessage resE = qrConfServiceRemote.queryQrConfByMerId(reqE);
			logger.info("【查询二维码配置接口】出参：" + resE);
			if( !"0000".equals(resE.getRetCode()) && !"00100003".equals(resE.getRetCode())){
				logger.info("查询二维码配置接口失败！");
				return ERROR;
			}
			Map<String, Object> map1 = resE.getResMap();
			List<QrConf> qrList =((List<QrConf>) map1.get("qrList"));
			if(qrList !=null && qrList.size()>0){
				String[] qrCodeList=new String[qrList.size()];
				int i=0;
				for (QrConf qrConf : qrList) {
					qrCodeList[i]=qrConf.getQrId();
					i++;
				}
				resMap.put("qrCodeList", qrCodeList);
			}else{
				resMap.put("qrCodeList", null);
			}
			//~~~~~~~~~~~~~~~~~~~查询处理流程接口（审核意见）~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage reqJoin = ReqMessageUtil.makeOpReq();
			reqJoin.put("merUniformId",StringUtil.trim(storeId));	//商户唯一标识
			reqJoin.put("handleRole","02");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他
			logger.info("【查询处理流程接口】入参："+ reqJoin);
			ResMessage resJoin = joinFlowServiceRemote.queryJoinFlowList(reqJoin);
			logger.info("【查询处理流程接口】出参："+ resJoin);
			if(!"0000".equals(resJoin.getRetCode())){
				logger.info("查询出来流程接口失败！");
				return ERROR;
			}
			List<JoinFlow> joinFlows = (List<JoinFlow>) resJoin.getResMap().get("joinFlowList");
			if(joinFlows.size() > 0){
				ListSort(joinFlows); //排序后取最新
				resMap.put("opinion", joinFlows.get(joinFlows.size() - 1).getRemark());	//审核意见
			}else {
				resMap.put("opinion", "");	//审核意见
			}
			List<Map<String, Object>> list = new ArrayList<Map<String,Object>>();
			provinceList = ProviceCityInfHelper.getAllProvice();
			list.add(resMap);
			pageView.setRecords(list);
			return "merchantRevise";
		} catch (Exception e) {
			logger.error("修改立码付商户页面初始化接口失败",e);
		}
		return ERROR;
	}
	
	/**
	 * 对返回的驳回信息进行排序
	 * @param list
	 */
	private static void ListSort(List<JoinFlow> list) {
		Collections.sort(list, new Comparator<JoinFlow>() {
			public int compare(JoinFlow o1, JoinFlow o2) {
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				try {
					Date dt1 = format.parse(o1.getIntime());
					Date dt2 = format.parse(o2.getIntime());
					if (dt1.getTime() > dt2.getTime()) {
						return 1;
					} else if (dt1.getTime() < dt2.getTime()) {
						return -1;
					} else {
						return 0;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return 0;
			}
		});
	}
	/**
	 * 修改商户名称校验接口
	 * @return
	 */
	public String checkStoreName(){
		logger.info("【修改商户名称校验接口】开始");
		try {
			String storeShortName = StringUtil.trim(request.getParameter("storeShortName"));
			if(StringUtil.isEmpty(storeShortName)){
				logger.info("获取商户简称为空！");
				response.getWriter().write("0");
				return null;
			}
			String merId = StringUtil.trim(request.getParameter("merId"));
			if(StringUtil.isEmpty(merId)){
				logger.info("获取商户号为空！");
				response.getWriter().write("0");
				return null;
			}
			//~~~~~~~~~~~~~~~~~~根据主商户号和店铺名称查询店铺信息接口~~~~~~~~~~~~~~~~~~~
			ReqMessage req = ReqMessageUtil.makeOpReq();
			req.put("merId", merId);
			req.put("storeShortName", merId);
			logger.info("【修改商户名称校验接口】入参" + req);
			ResMessage res = storeInfServiceRemote.countStoreInfByStoreNameAndMerId(req);
			if(!"0000".equals(res.getRetCode())){
				logger.info("根据主商户号和店铺名称查询店铺信息接口失败");
				response.getWriter().write("0");
				return null;
			}
			Integer storeCount = (Integer) res.getResMap().get("storeCount");
			if (storeCount > 0) {
				logger.info("已存在此商户号的商户名称");
				response.getWriter().write("0");
				return null;
			}
			logger.info("商户简称合格");
			response.getWriter().write("0000");
			return null;
		} catch (Exception e) {
			logger.error("商户简称校验失败！",e);
			return null;
		}
	}
	/**
	 * 修改立码付商户保存接口
	 * @return
	 */
	public String updateStoreInfo(){
		logger.info("【修改立码付商户保存接口】开始");
		try {
			String storeCategory1 = StringUtil.trim(request.getParameter("storeCategory1"));
			String storeCategory2 = StringUtil.trim(request.getParameter("storeCategory2"));
			String storeCategory3 = StringUtil.trim(request.getParameter("storeCategory3"));
			String storeCategory  = "";
		    if(StringUtil.isNotEmpty(storeCategory3)){
	        	storeCategory=storeCategory1+"&"+storeCategory2+"&"+storeCategory3;
	        }else{
	        	storeCategory=storeCategory1+"&"+storeCategory2;
	        }
//			String storeCategory = StringUtil.trim(request.getParameter("storeCategory"));//商户类别
			String payeeInidcardValid = StringUtil.trim(request.getParameter("payeeInidcardValid"));//证件有效期
			String storeAddrProv = StringUtil.trim(request.getParameter("merProvinceName"));//商户地址/省
			String storeAddrCity = StringUtil.trim(request.getParameter("merCityName"));//市
			String storeAddrArea = StringUtil.trim(request.getParameter("merAreaName"));//区
			String lable_one = StringUtil.trim(request.getParameter("lable_one"));//标签一
			String lable_two = StringUtil.trim(request.getParameter("lable_two"));//标签二
			String storeFullAddr = StringUtil.trim(request.getParameter("storeFullAddr"));//商户详细地址
			String storeShortName = StringUtil.trim(request.getParameter("storeShortName"));//商户简称
			String payeeMobile = StringUtil.trim(request.getParameter("payeeMobile"));//收款人手机号
			String merId = StringUtil.trim(request.getParameter("merId"));
			if(StringUtil.isEmpty(storeId)){
				logger.info("获取店铺号失败！");
				return ERROR;
			}
			if(StringUtil.isEmpty(merId)){
				logger.info("获取商户号失败！");
				return ERROR;
			}
			//~~~~~~~~~~~~~~~~~~~~~~店铺部署详情接口，查询店铺信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ReqMessage req = ReqMessageUtil.makeOpReq();
			req.put("storeId",storeId);
			logger.info("【查询店铺部署详情接口】入参：" + req);
			ResMessage  res = storeInfServiceRemote.getStoreInfByPri(req);
			logger.info("【查询店铺部署详情接口】出参：" + res);
			if( !RetCode.SUCCESS.equals(res.getRetCode())){
				logger.info("查询店铺部署详情接口失败！");
				return ERROR;
			}
			MerchantInfo merchantInfo = (MerchantInfo) res.getResMap().get("merchantInfo");
			if(merchantInfo ==null ||merchantInfo.equals("")){		//无数据
				logger.info("查询收款人信息无数据merId："+merId);
				return ERROR;
			}
			//是否修改了证件有效期
			String cardTime =StringUtil.trim(merchantInfo.getPayeeInidcardValid());
			if((null != cardTime && null != payeeInidcardValid && !payeeInidcardValid.equals(cardTime)) || (null == cardTime && null != payeeInidcardValid)){
				//校验证件有效期是否大于当前时间
				Date now = new Date();
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
				String nowDate = dateFormat.format( now ); 
				logger.info("当前日期为：" + nowDate + "修改证件有效期为：" + payeeInidcardValid );
			    if(payeeInidcardValid.compareTo(nowDate) <= 0){
			    	logger.info("证件有效期小于当前日期！");
			    	return ERROR;
			    }
				//修改所有子商户证件有效期
				ReqMessage reqCard = ReqMessageUtil.makeOpReq();
				reqCard.put("merId",merId);	//主商户号
				reqCard.put("payeeInidcardValid",payeeInidcardValid);	//证件有效期
				logger.info("【根据主商户号修改所有子商户证件有效期】入参" + reqCard);
				ResMessage resCard = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(reqCard);
				logger.info("【根据主商户号修改所有子商户证件有效期】出参" + resCard);
				if(!"0000".equals(resCard.getRetCode())){
					logger.info("根据主商户号修改所有子商户证件有效期失败！");
					return ERROR;
				}
				logger.info("根据主商户号修改所有子商户证件有效期成功！");
				// 修改主商户证件有效期
				ReqMessage reqCardMer = ReqMessageUtil.makeOpReq();
				reqCardMer.put("storeId",merId); //主商户编号，即主商户ID
				reqCardMer.put("payeeInidcardValid",payeeInidcardValid);	//证件有效期
				logger.info("【修改主商户证件有效期】入参：" + reqCardMer);
				ResMessage resCardMer = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(reqCardMer);
				logger.info("【修改主商户证件有效期】出参：" + resCardMer);
				if(!"0000".equals(resCardMer.getRetCode())){
					logger.info("修改主商户证件有效期失败！");
					return ERROR;
				}
				merchantInfo.setPayeeInidcardValid(payeeInidcardValid);
			}
			//是否修改了手机号
			String mobile = StringUtil.trim(merchantInfo.getPayeeMobileId());
		    payeeMobile = StringUtil.trim(payeeMobile);
			if((mobile == null && payeeMobile != null) || (payeeMobile != null && mobile != null && !payeeMobile.equals(mobile))){
				//校验店铺数量，批量修改商户所有的收款人手机号
				//根据主商户号查询店铺详情列表接口
				ReqMessage reqMob = ReqMessageUtil.makeOpReq();
				reqMob.put("merId",merId);
				logger.info("【查询店铺部署详情列表接口】入参：" + reqMob);
				ResMessage resMo = storeInfServiceRemote.getStoreInfList(reqMob);
				logger.info("【查询店铺部署详情列表接口】出参：" + resMo);
				if(!"0000".equals(resMo.getRetCode())){
					logger.info("查询店铺部署详情列表接口失败！");
					return ERROR;
				}
				Integer totalSize = (Integer) resMo.getResMap().get("totalSize");
				List<MerchantInfo> storeInfs = (List<MerchantInfo>) resMo.getResMap().get("storeInfList");
				if (totalSize > 1) {	//大于1，说明有其它子店铺
					for (int i = 0; i < storeInfs.size(); i++) {	//不能修改手机号
						if (storeInfs.get(i).getRegisterProcsState().equals("06")
								|| storeInfs.get(i).getRegisterProcsState().equals("07")
								|| storeInfs.get(i).getRegisterProcsState().equals("08")
								|| storeInfs.get(i).getRegisterProcsState().equals("09")) {
							logger.info("手机号不可以修改");
							return ERROR;
						}
					}
					//修改所有子店铺手机号
					reqMob.put("payeeMobileId",payeeMobile);//手机号
					logger.info("【根据主商户号修改所有子商户手机号码接口】入参" + reqMob);
					ResMessage resMobS = storeInfServiceRemote.updateStoreByMerIdOrStoreId(reqMob);
					logger.info("【根据主商户号修改所有子商户手机号码接口】出参" + resMobS);
					if(!"0000".equals(resMobS.getRetCode())){
						logger.info("根据主商户号修改所有子商户手机号码接口失败！");
						return ERROR;
					}
					logger.info("修改子商户手机号成功！");
				}
				//修改主商户手机号
				ReqMessage reqMobMer = ReqMessageUtil.makeOpReq();
				reqMobMer.put("storeId",merId); //主商户编号，即主商户ID
				reqMobMer.put("payeeMobileId",payeeMobile);	//手机号
				logger.info("【修改主商户手机号接口】入参：" + reqMobMer);
				ResMessage resMobMer = storeInfServiceRemote.updateStoreByMerIdOrStoreId(reqMobMer);
				logger.info("【修改主商户手机号接口】出参" + resMobMer);
				if(!"0000".equals(resMobMer.getRetCode())){
					logger.info("修改主商户手机号接口失败");
					return ERROR;
				}
				logger.info("修改主商户手机号成功！");
				merchantInfo.setPayeeMobileId(payeeMobile);
			}
			//更新店铺信息接口
			if(StringUtil.isNotEmpty(storeCategory)){
				merchantInfo.setStoreCategory(storeCategory);
			}
			if(StringUtil.isNotEmpty(lable_one)){
				merchantInfo.setLabelOne(lable_one);
			}
			if(StringUtil.isNotEmpty(lable_two)){
				merchantInfo.setLabelTwo(lable_two);
			}
			if(StringUtil.isNotEmpty(storeFullAddr)){
				merchantInfo.setStoreFullAddr(storeFullAddr);
			}
			if(StringUtil.isNotEmpty(storeShortName)){
				merchantInfo.setStoreShortName(storeShortName);	//商家简称
			}
			if(StringUtil.isNotEmpty(storeAddrProv)) {
				merchantInfo.setStoreAddrProv(storeAddrProv);
			}
			if(StringUtil.isNotEmpty(storeAddrCity)){
				merchantInfo.setStoreAddrArea(storeAddrArea);
			}
			if(StringUtil.isNotEmpty(storeAddrArea)){
				merchantInfo.setStoreAddrArea(storeAddrArea);
			}
			Map<String, Object> storeMap = SaasPropertyUtil.javaBeanToMapO(merchantInfo);
			ReqMessage reqUp = ReqMessageUtil.makeOpReq();
			reqUp.putAll(storeMap);
			logger.info("【更新店铺信息接口】入参：" + reqUp);
			ResMessage resUp = storeInfServiceRemote.updateStoreInfAll(reqUp);
			logger.info("【更新店铺信息接口】出参：" + resUp);
			if(!"0000".equals(resUp.getRetCode())){
				logger.info("更新店铺信息接口调用失败！");
				return ERROR;
			}
			logger.info("更新店铺信息接口调用成功！");
//			return "batchMerchantList";
			return "updateSuccess";
		} catch (Exception e) {
			logger.error("更新店铺信息接口调用失败！",e);
			return ERROR;
		}
	}
	
	/**
	 * 下载图片
	 */
	public String downPic(){
		String storeId = StringUtil.trim(request.getParameter("storeId"));
		String storeshortname = StringUtil.trim(request.getParameter("storeShortName"));
		if(StringUtil.isEmpty(storeId)){
			logger.info("获取店铺号失败！");
			return ERROR;
		}
		logger.info("【根据店铺编号打包下载所有图片zip】开始");
		Long startTime = System.currentTimeMillis();
//		saasPlat.comp.uploadPath=/usr/mpsp/duizhang/qualification/apply
		String serverPath =PropertyUtil.getStrValue("spEnterpriseWeb_config.properties", "saasPlat.comp.uploadPath","");
		String zipPath=PropertyUtil.getStrValue("spEnterpriseWeb_config.properties", "saas.downImgAllByZip.path","");
//		saas.downImgAllByZip.path=/usr/mpsp/AppData/imgdownload
		List<String> imgList=new ArrayList<String>();
		logger.info("【downImgAllByZip】【参数初始化完成耗时】= " + (System.currentTimeMillis() - startTime) + " 毫秒");
		//1.根据商铺编号查询所有图片的名字
		if(StringUtil.isEmpty(storeId)){
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，缺少请求参数店铺id");
			return ERROR;
		}
		MerchantInfoVo merchantInfoVo =preStoreInf(storeId);
		if(merchantInfoVo==null){
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，根据店铺编号查询商铺信息失败");
			return ERROR;
		}
		String path = serverPath+File.separator+storeId+File.separator;
		//2.拼装完整的图片地址，并放入list中
		if(!StringUtil.isEmpty(merchantInfoVo.getCategoryCardPhotoFront())){
			String newpath=path+merchantInfoVo.getCategoryCardPhotoFront(); 
			File file=new File(path, merchantInfoVo.getCategoryCardPhotoFront());
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
			
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getCategoryCardPhotoCon())){
			String newpath=path+merchantInfoVo.getCategoryCardPhotoCon();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证背面图片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getPayeeCardPhotoFront())){
			String newpath=path+merchantInfoVo.getPayeeCardPhotoFront();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，收款人身份证正面图片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getPayeeCardPhotoCon())){
			String newpath=path+merchantInfoVo.getPayeeCardPhotoCon();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，收款人身份证反面面图片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getShopSignPhotoFront())){
			String newpath=path+merchantInfoVo.getShopSignPhotoFront();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，店铺招牌照片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getShopSignPhotoCon())){
			String newpath=path+merchantInfoVo.getShopSignPhotoCon();  
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，店铺内景照片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getBusiLicensePhoto())){
			String newpath=path+merchantInfoVo.getBusiLicensePhoto();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，营业执照照片库里暂无");
		}
		if(!StringUtil.isEmpty(merchantInfoVo.getAuthCertPhoto())){
			String newpath=path+merchantInfoVo.getAuthCertPhoto();
			File file=new File(newpath);
			if(file.exists()){
				imgList.add(newpath);
			}else{
				logger.info("----★----★--根据店铺编号打包下载所有图片zip，经营者身份证正面图片服务器上找不到该图片");
			}
		}else{
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，授权函照片库里暂无");
		}
		if(imgList==null||imgList.size()<1){
			logger.info("----★----★--根据店铺编号打包下载所有图片zip，暂无图片可以下载");
			return ERROR;
		}
		
		//3.生成zip文件,下载并删除
		RandomCode ran = new RandomCode();
//		String zipFileName = zipPath+File.separator+ran.getSix()+"-"+storeId+".zip";
		String zipFileName = zipPath+File.separator+storeshortname+"（"+storeId+ "）"+".zip";
		logger.info(String.format("----★----★--根据店铺编号打包下载所有图片zip，打包地址：【%s】",zipFileName));
		File zipFile = new File(zipFileName);
		synchronized(zipFile) {
			 try {
				ZipUtil.zip(zipFile, imgList);
				logger.info("【downImgAllByZip】【文件打包完成耗时】= " + (System.currentTimeMillis() - startTime) + " 毫秒");
			} catch (IOException e) {
				logger.error("下载文件错误：打包文件错误！",e);
				return ERROR;	
			}
		}
		//下载文件
		try {
			downloadFile = new File(zipFileName);
			downloadFileName = StringUtil.trim(downloadFile.getName());
			downloadFileName = new String(downloadFileName.getBytes(), "ISO8859-1");
			logger.info("【downImgAllByZip】【文件下载完成耗时】= " + (System.currentTimeMillis() - startTime) + " 毫秒");
		} catch (Exception e) {
			logger.error("下载文件错误：打包文件错误！",e);
			return ERROR;
		}
		if (null == downloadFile || !downloadFile.exists()) {
			logger.error("下载文件为空");
			return ERROR;	
		}
		logger.info("【downImgAllByZip】【结算记录文件下载完成整体耗时】= " + (System.currentTimeMillis() - startTime) + " 毫");	
		logger.info("----★----★--根据店铺编号打包下载所有图片zip，结束");
		return "downImgAll";
	}
	
	public InputStream getInputStream() throws Exception {
		if (downloadFile != null) {
			FileInputStream fis = null;
			try {
				fis = new FileInputStream(downloadFile);
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
			return fis;
		} else {
			throw new Exception("downloadFile can not be null!");
		}
	}
	
	private MerchantInfoVo preStoreInf(String storeId){
		ReqMessage req = ReqMessageUtil.makeOpReq();
		req.put("storeId",storeId);
		logger.info(" 【查询店铺信息 】入参："+req);
		ResMessage res = storeInfServiceRemote.getStoreInfByPri(req);
		logger.info(" 【查询店铺信息 】出参："+res);
		//4.处理结果
		logger.info(String.format("查询店铺返回结果:【%s】", res.toString()));
		if(!RetCode.SUCCESS.equals( res.getRetCode())){
			logger.info("查询店铺信息 失败！");
			return null;
		}
		MerchantInfo merchantInfo = (MerchantInfo) res.getValue("merchantInfo");
		return new MerchantInfoVo(merchantInfo);
		
	}
	
	public PageView getPageView() {
		return pageView;
	}
	public void setPageView(PageView pageView) {
		this.pageView = pageView;
	}
	public List<ProviceCityInf> getProvinceList() {
		return provinceList;
	}
	public void setProvinceList(List<ProviceCityInf> provinceList) {
		this.provinceList = provinceList;
	}
	public String getStoreId() {
		return storeId;
	}
	public void setStoreId(String storeId) {
		this.storeId = storeId;
	}
	public String getStoreshortname() {
		return storeshortname;
	}
	public void setStoreshortname(String storeshortname) {
		this.storeshortname = storeshortname;
	}
	public String getPayeename() {
		return payeename;
	}
	public void setPayeename(String payeename) {
		this.payeename = payeename;
	}
	public String getStoreType() {
		return storeType;
	}
	public void setStoreType(String storeType) {
		this.storeType = storeType;
	}
	public String getIntimeStart() {
		return intimeStart;
	}
	public void setIntimeStart(String intimeStart) {
		this.intimeStart = intimeStart;
	}
	public String getIntimeEnd() {
		return intimeEnd;
	}
	public void setIntimeEnd(String intimeEnd) {
		this.intimeEnd = intimeEnd;
	}
	public String getRegisterProcsState() {
		return registerProcsState;
	}
	public void setRegisterProcsState(String registerProcsState) {
		this.registerProcsState = registerProcsState;
	}
	public String getPayeeMobileId() {
		return payeeMobileId;
	}
	public void setPayeeMobileId(String payeeMobileId) {
		this.payeeMobileId = payeeMobileId;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public String getMerId() {
		return merId;
	}
	public void setMerId(String merId) {
		this.merId = merId;
	}
	public String getAgentId() {
		return agentId;
	}
	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}

	public File getDownloadFile() {
		return downloadFile;
	}
	public void setDownloadFile(File downloadFile) {
		this.downloadFile = downloadFile;
	}
	public String getDownloadFileName() {
		return downloadFileName;
	}
	public void setDownloadFileName(String downloadFileName) {
		this.downloadFileName = downloadFileName;
	}
	public String getIsDel() {
		return isDel;
	}
	public void setIsDel(String isDel) {
		this.isDel = isDel;
	}
	
}
